<?php
class PersonasController extends AppController {

	var $name = 'Personas';
	var $components = array('RequestHandler');
	
	function index(){
		$this->layout="ajax";		
		if($this->JQGridPaginate->isGrid){
			$fields = array(
			'Persona.id',
			'Persona.nombre',
			'Persona.ap_paterno',
			'Persona.ap_materno',
			'Persona.fech_nacimiento',
			'Persona.direccion',
			'Persona.telefono',
			'Persona.dni',
			'Persona.estado_civil',
			'Persona.sexo',
			'Persona.nombre_completo',
			//'"Demandatipo"."descripciontipo" AS "Demanda__demandatipo"'
			);
/*
			'Deposito.numero_operacion',
			'Deposito.monto',
			'"Usuario"."username" AS "Deposito__usuario"',
			'"Deposito"."created"::date AS "Deposito__created"',
			'"Estado"."descripcion" AS "Deposito__estado"')*/;		
	
			$this->JQGridPaginate->recursive = 0;
			$this->JQGridPaginate->cakefields = $fields;
			echo $this->JQGridPaginate->paginate("Persona");
			$this->autoRender = false;
		
		}elseif($this->RequestHandler->isPost()){	
			$oper = $this->params['form']['oper'];
			if($oper == "add"){
			    //$this->data['Deposito']['usuario_id'] = 1;
			   // $this->data['Demanda']['demandatipo_id'] = 1;
				//var_dump ($this->data['Demanda']);
				$this->Persona->create();				 
			}elseif ($oper == "edit"){
				$this->data['Persona']['id'] = $this->params['form']['id'];
			}elseif ($oper == "del"){
				$this->data['Persona']['id'] = $this->params['form']['id'];
				//$this->data['Demanda']['estado_id'] = 2;				
			}
			//var_dump($this->data['Demanda']);exit;
			Configure::write('debug',2);
			pr($this->data);
			$this->Persona->save($this->data['Persona']);
			echo json_encode($this->Persona->visualizarError($this->Persona->validationErrors));
			$this->autoRender = false;
		}		
	}
	/*
	function listafamilias(){
		$this->layout="ajax";
		$listaFamilias = $this->Familia->find('list',array('fields'=>array('Familia.id','Familia.descripcion'),
															'order'=>'Familia.descripcion'));
		echo json_encode($listaFamilias);
		$this->autoRender = false;
	}*/
}
